package com.fc.test.controller.admin;

import com.fc.test.util.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseController;
import com.fc.test.common.domain.AjaxResult;
import com.fc.test.model.auto.TAbbMember;
import com.fc.test.model.custom.TableSplitResult;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.model.custom.TitleVo;
import com.fc.test.service.TAbbMemberService;
import io.swagger.annotations.Api;

import java.util.Date;

@Controller
@RequestMapping("TAbbMemberController")
@Api(value = "")
public class TAbbMemberController extends BaseController{

	private String prefix = "admin/tAbbMember";
	@Autowired
	private TAbbMemberService tAbbMemberService;

	@GetMapping("view")
	@RequiresPermissions("gen:tAbbMember:view")
    public String view(Model model)
    {
		String str="";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
        return prefix + "/list";
    }


	@PostMapping("list")
	@RequiresPermissions("gen:tAbbMember:list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchTxt,String address,String isvip,String starttime,String endtime){
		PageInfo<TAbbMember> page=tAbbMemberService.list(tablepar,searchTxt,address,isvip,starttime,endtime);
		TableSplitResult<TAbbMember> result=new TableSplitResult<TAbbMember>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}

	/**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }


	@PostMapping("add")
	@RequiresPermissions("gen:tAbbMember:add")
	@ResponseBody
	public AjaxResult add(TAbbMember tAbbMember,Model model){
		int b=tAbbMemberService.insertSelective(tAbbMember);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}

	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	@PostMapping("remove")
	@RequiresPermissions("gen:tAbbMember:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=tAbbMemberService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}


	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("TAbbMember", tAbbMemberService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

	/**
     * 修改保存
     */
    @RequiresPermissions("gen:tAbbMember:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAbbMember record)
    {
        return toAjax(tAbbMemberService.updateByPrimaryKeySelective(record));
    }


	/**
	 * 升级为vip
	 */
	@RequiresPermissions("gen:tAbbMember:shengji")
	@PostMapping("/shengji")
	@ResponseBody
	public AjaxResult shengji(TAbbMember record)
	{
		record.setIsvip(1);
		record.setVipendtime(DateUtil.addDays(new Date(),365));
		record.setYuliu2(DateUtil.getCurrentDateTimeStr());
		return toAjax(tAbbMemberService.updateByPrimaryKeySelective(record));
	}
	/**
	 * 取消vip
	 */
	@RequiresPermissions("gen:tAbbMember:quxiao")
	@PostMapping("/quxiao")
	@ResponseBody
	public AjaxResult quxiao(TAbbMember record)
	{
		record.setIsvip(0);
		record.setVipendtime(new Date());
		return toAjax(tAbbMemberService.updateByPrimaryKeySelective(record));
	}




}
